*===================================================================
cd "C:\Users\s12146\Dropbox\research\corona"
*cd "/Users/steffenjuranek/Dropbox/research/corona"
import excel "20200821hospital.xlsx", sheet("hospital") firstrow clear
save "20200821FINAL.dta", replace

use 20200708FINAL.dta, clear				  

/*
rename tests_cum tests_cum_SJ
joinby country date using testdata.dta, unmatched(master)
drop _merge
*/


gen inhabitants=0
replace inhabitants=5367580 if country=="Norway"
replace inhabitants=10327589 if country=="Sweden"
replace inhabitants=5827463 if country=="Denmark"

/*
gen hospital_capacity=floor(beds2017*inhabitants/1000)
gen intensive_care_capacity=floor(icuccbbeds*inhabitants/100000)
*/

encode country, gen(id)
xtset id date
label var date "date"


replace tests_cum=tests_cum_interpolated if country=="Sweden"


bysort id (date): gen cases_cum_official=sum(new_cases_official)
label var cases_cum_official "persons positively tested (cumulative)"
xtline cases_cum_official if date>=td(18mar2020), overlay scheme(s2mono)
*fig_cases_cum
gen cases_cum_official_inh=cases_cum_official/inhabitants*1000000
label var cases_cum_official_inh "persons positively tested per 1mn inhabitants (cum.)"
xtline cases_cum_official_inh if date>=td(18mar2020), overlay scheme(s2mono)


label var new_cases_official "persons positively tested"
xtline new_cases_official if date>=td(18mar2020), overlay scheme(s2mono)
*fig_cases
gen new_cases_official_inh=new_cases_official/inhabitants*1000000
label var new_cases_official_inh "persons positively tested per 1mn inhabitants"
xtline new_cases_official_inh if date>=td(18mar2020), overlay scheme(s2mono) 



label var total_deaths "Total number of deaths"
xtline total_deaths if date>=td(18mar2020), overlay scheme(s2mono)
*fig_total_deaths
gen total_deaths_inh=total_deaths/inhabitants*1000000
label var total_deaths_inh "Total number of deaths per 1mn inhabitants"
xtline total_deaths_inh if date>=td(18mar2020) & date<=td(21apr2020), overlay plot1(lc(red)) plot2(lc(black)) graphregion(margin(3 8 2 4)) xlabel(`=d(20mar2020)' `=d(25mar2020)' `=d(30mar2020)' `=d(04apr2020)' `=d(09apr2020)' `=d(14apr2020)'  `=d(19apr2020)',format(%tdddMon) labsize(large)) ylabel(,labsize(large)) legend(size(large)) xtitle("") ytitle("")   //xlabel(, angle(45))
xtline total_deaths_inh if date>=td(05mar2020) & date<=td(30june2020), overlay plot1(lc(red)) plot2(lc(black)) graphregion(margin(3 8 2 4)) xlabel(`=d(08mar2020)' `=d(22mar2020)' `=d(05apr2020)' `=d(19apr2020)' `=d(03may2020)' `=d(17may2020)' `=d(31may2020)' `=d(14june2020)' `=d(28june2020)',format(%tdddMon) labsize(medium)) ylabel(,labsize(large)) legend(size(large)) xtitle("") ytitle("")   //xlabel(, angle(45))



label var tests_cum "Total number of tests"
xtline tests_cum if date>=td(15may2020), overlay scheme(s2mono)
*fig_tests_cum
gen tests_cum_inh=tests_cum/inhabitants*1000000
label var tests_cum_inh "Cumulative number of tests per 1mn inh."
xtline tests_cum_inh if date<=td(15may2020) & date>td(01mar2020), overlay scheme(s2mono) xtitle("") xlabel(`=d(01mar2020)' `=d(15mar2020)' `=d(01apr2020)' `=d(15apr2020)' `=d(01may2020)' `=d(15may2020)',format(%tdddMon))


label var tests_new "New tests"
xtline tests_new if date>=td(18mar2020), overlay scheme(s2mono) 
*fig_cases
gen tests_new_inh=tests_new/inhabitants*1000000
label var tests_new_inh "New tests per 1mn inhabitants"
xtline tests_new_inh if date>=td(18mar2020), overlay scheme(s2mono) 









label var hospitalized "persons in hospital"
xtline hospitalized if date>=td(18mar2020), overlay scheme(s2mono)
*fig_hospital
gen hospitalized_inh=hospitalized/inhabitants*1000000
label var hospitalized_inh "persons in hospital per 1mn inhabitants"
xtline hospitalized_inh if date>=td(05mar2020) & date<=td(30june2020), overlay plot1(lc(red)) plot2(lc(black)) graphregion(margin(3 8 2 4)) xlabel(`=d(08mar2020)' `=d(22mar2020)' `=d(05apr2020)' `=d(19apr2020)' `=d(03may2020)' `=d(17may2020)' `=d(31may2020)' `=d(14june2020)' `=d(28june2020)',format(%tdddMon) labsize(medium)) ylabel(,labsize(large)) legend(size(large)) xtitle("") ytitle("")   //xlabel(, angle(45))


*xtline hospitalized if date>td(08mar2020) & country=="Sweden", overlay scheme(s2mono) tline(25mar2020) yline(22951)


*gen date2=date
*di date2
label var intensive_care "persons in intensive care"
xtline intensive_care if date>=td(18mar2020), overlay scheme(s2mono)
*fig_intensive_care
gen intensive_care_inh=intensive_care/inhabitants*1000000
label var intensive_care_inh "persons in intensive care per 1mn inhabitants"
xtline intensive_care_inh if date>=td(05mar2020) & date<=td(30june2020), overlay plot1(lc(red)) plot2(lc(black)) graphregion(margin(3 8 2 4)) xlabel(`=d(08mar2020)' `=d(22mar2020)' `=d(05apr2020)' `=d(19apr2020)' `=d(03may2020)' `=d(17may2020)' `=d(31may2020)' `=d(14june2020)' `=d(28june2020)',format(%tdddMon) labsize(medium)) ylabel(,labsize(large)) legend(size(large)) xtitle("") ytitle("")   //xlabel(, angle(45))


/*
xtline intensive_care if date>=td(18mar2020) & country=="Denmark", overlay scheme(s2mono) tline(25mar2020) yline(390) yscale(range(0 400)) ylabel(0(100)400)
xtline intensive_care if date>=td(18mar2020) & country=="Norway", overlay scheme(s2mono) tline(25mar2020) yline(429) yscale(range(0 450)) ylabel(0(100)400)
xtline intensive_care if date>=td(18mar2020) & country=="Sweden", overlay scheme(s2mono) tline(25mar2020) yline(599) yscale(range(0 620)) ylabel(0(100)600)
*/


label var intensive_care_new "persons new in intensive care"
xtline intensive_care_new  if date>=td(18mar2020), overlay scheme(s2mono)
*fig_intensive_care_new
gen intensive_care_new_inh=intensive_care_new/inhabitants*1000000
label var intensive_care_new_inh "persons new in intensive care per 1mn inhabitants"
xtline intensive_care_new_inh if date>=td(18mar2020), overlay scheme(s2mono) 

label var respirator "persons on respirator"
xtline respirator if date>=td(18mar2020),  overlay scheme(s2mono) 
*fig_respirator
gen respirator_inh=respirator/inhabitants*1000000
label var respirator_inh "person son respirator per 1mn inhabitants"
xtline respirator_inh if date>=td(18mar2020),  overlay scheme(s2mono) 




